package solitaire.deck;

import java.awt.geom.Point2D;
import java.util.ArrayList;

import javax.swing.JOptionPane;

import solitaire.deck.Card.Rank;

public class Validation extends PileCollection
{
	/*
	public boolean isPileEmpty()
	{
		for (Pile rec : this)
		{
			if (rec.getPileLength() == 0)
			{
				return true;
			}			
		}
		return false;
	}
	*/
	
	public static boolean canBePlacedOnEmptySlot(Pile p, CardCollection cc)
	{
				
		if (p == null || cc == null)
			{return false;}
		if (p.getCards().size()>0)
			{return false;}
		if (cc.getFirst().rank() == Rank.KING)
			{return true;}		
		return false;
	}
	
	public static boolean canCardBePlacedOnTopOfPlaypile(Pile p,CardCollection cc)
	{
		if (p==null){return false;}
		if (cc==null){return false;}
		
		Card first = cc.getFirst();
		Card last = p.getCards().getLast();
		CardCollection pile = p.getCards();
		
		
		if (pile.size()!=0)
		{
			if (cc.size() != 0)
			{
				if (last.suit() == first.suit())
				{
					if (last.rank().ordinal() == first.rank().ordinal()+1)
					{
						return true;
					}
				}			
			}
		}
		return false;
	}
	
	public static boolean canCardBePlacedOnAce(Pile p, CardCollection cc)
	{
		if (p==null)
			return false;
		
		if(cc.size() != 1)
			return false;
		
		Card first = cc.getFirst();
		Card last = p.getCards().getLast();

		
		if(last == null)
		{
			if(first.rank() == Rank.ACE)
				return true;
			else
				return false;
				
		}
		else
		{
			if (first.suit() == last.suit()
					&& last.rank().ordinal()+1 == first.rank().ordinal())
			{
				return true;
			}
			else 
				return false;
		}
	}
	
	
	public static Pile canCardBeDoubleClickedOnAce(CardCollection c, PileCollection pc)
	{
		if (c==null){return null;}
		
		Card first = c.getFirst();
		
		for (Pile p : pc)
		{
			Card last = p.getCards().getLast();
			
			if(last == null)
			{
				if(first.rank() == Rank.ACE)
					return p;
				else
					return null;

			}
			else if (last.suit() == first.suit() &&
					last.rank().ordinal()+1 == first.rank().ordinal())
			{
				return p;
			}
			
		}
		
		return null;
		
	}

}
